package org.hydrakyoufeng.stuplatform.controller;

import io.swagger.v3.oas.annotations.tags.Tag;
import org.hydrakyoufeng.stuplatform.dto.ChapterDTO;
import org.hydrakyoufeng.stuplatform.dto.ChapterListDTO;
import org.hydrakyoufeng.stuplatform.dto.ChapterSortDTO;
import org.hydrakyoufeng.stuplatform.service.ChapterService;
import org.hydrakyoufeng.stuplatform.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("chapter")
@Tag(name = "章节")
public class ChapterController {

    private final ChapterService chapterService;

    @Autowired
    public ChapterController(ChapterService chapterService) {
        this.chapterService = chapterService;
    }


    /**
     * 查询列表
     * @param dto
     * @return
     * @throws Exception
     */
    @PostMapping("queryList")
    public ResponseEntity queryList(@RequestBody ChapterListDTO dto) throws Exception {
        return ResponseEntity.ok(chapterService.queryList(dto));
    }

    /**
     * 更新排序
     * @param dto
     * @return
     * @throws Exception
     */
    @PostMapping("updateSort")
    public ResponseEntity updateSort(@RequestBody ChapterSortDTO dto) throws Exception {
        return ResponseEntity.ok(chapterService.updateSort(dto));
    }

    /**
     * 删除章节
     * @param id
     * @return
     * @throws Exception
     */
    @DeleteMapping("delete/{id}")
    public ResponseEntity delete(@PathVariable("id") Integer id) throws Exception  {
        return ResponseEntity.ok(chapterService.delete(id));
    }

    /**
     * 添加章节信息
     * @param chapterDTO
     * @return
     * @throws Exception
     */
    @PostMapping("insert")
    public ResponseEntity insert(@RequestBody ChapterDTO chapterDTO) throws Exception  {
        return ResponseEntity.ok(chapterService.insert(chapterDTO));
    }


    /**
     * 修改章节信息
     * @param chapterDTO
     * @return
     * @throws Exception
     */
    @PostMapping("update")
    public ResponseEntity update(@RequestBody ChapterDTO chapterDTO) throws Exception  {
        return ResponseEntity.ok(chapterService.update(chapterDTO));
    }

    /**
     * 用户查询课程中的章节列表：不分页
     * @param course_id
     * @return
     * @throws Exception
     */
    @GetMapping("queryUserList/{course_id}")
    public ResponseEntity queryUserList(@PathVariable Integer course_id) throws Exception {
        return ResponseEntity.ok(chapterService.queryUserList(course_id));
    }
}